package com.zhilehuo.service.impl;

import com.zhilehuo.common.BaseResponse;
import com.zhilehuo.mapper.WordMapper;
import com.zhilehuo.model.request.ChangeWordRequest;
import com.zhilehuo.service.IWordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class WordServiceImpl implements IWordService {

    @Resource
    private WordMapper wordMapper;
    @Override
    public BaseResponse<String> updatePinyin(ChangeWordRequest changeWordRequest) {

        Integer paragraphId = changeWordRequest.getId();
        String selectedCharacter = changeWordRequest.getSelectedCharacter();
        String wordsIdStr = changeWordRequest.getWordsId();
        if (wordsIdStr == null || wordsIdStr.isEmpty()) {
            return new BaseResponse<>(400, null, "wordsId 为空");
        }
        Integer wordsId = Integer.valueOf(wordsIdStr);

        if (paragraphId == null) {
            return new BaseResponse<>(400, null, "paragraphId 为空");
        }
        if (selectedCharacter == null || selectedCharacter.isEmpty()) {
            return new BaseResponse<>(400, null, "selectedCharacter 为空");
        }

        wordMapper.updatePinyin(paragraphId,wordsId, selectedCharacter);


        return new BaseResponse<>(200,"更新成功");
    }
}
